package edu.bbu.bs.backend.model;

import javax.persistence.Column;
import javax.persistence.Entity;

@Entity
public class Author extends BaseEntity implements Comparable<Author> {

	private static final long serialVersionUID = 1L;
	private String firstName;
	private String lastName;
	
	public Author() {
		this (null, null, null);
	}
	
	public Author(final String firstName, final String lastName) {
		this (null, firstName, lastName);
	}
	
	public Author (final Long id, final String firstName, final String lastName) {
		super(id);
		this.firstName = firstName;
		this.lastName = lastName;
	}

	@Column (name = "firstName")
	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	@Column (name = "lastName")
	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	
	@Override
	public String toString() {
		return "id: [" + getId() + "] " + firstName + " " + lastName;
	}

	@Override
	public int compareTo(Author author) {
		final int cmp = this.getLastName().compareTo(author.getLastName());
		return cmp != 0 ? cmp : this.getFirstName().compareTo(author.getFirstName());
	}
	
	
}

